import { createRouter, createWebHistory } from 'vue-router'
import { useUserStore } from '@/stores'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    { path: '/login', component: () => import('@/components/login/LoginPage.vue') },
    {
      path: '/',
      component: () => import('@/components/layout/LayoutContainer.vue'),
      redirect: '/plan/planoverview',
      children: [
        {
          path: '/auth/classmanage',
          component: () => import('@/components/auth/ClassManage.vue'),
        },
        {
          path: '/auth/usermanage',
          component: () => import('@/components/auth/UserManage.vue')
        },
        {
          path: '/auth/coursemanage',
          component: () => import('@/components/auth/CourseManage.vue')
        },
        {
          path: '/plan/planoverview',
          component: () => import('@/components/plan/PlanOverview.vue')
        },
        {
          path: '/auth/teachermanage',
          component: () => import('@/components/auth/TeacherManage.vue')
        },
      ]
    }
  ]
})
router.beforeEach((to) => {
  const useStore = useUserStore()
  if (!useStore.token && to.path !== '/login') return '/login'
})
export default router